package com.dingli.service.impl;

import com.dingli.framework.entity.Member;
import com.dingli.framework.entity.Recruit;
import com.dingli.framework.entity.Resume;
import com.dingli.framework.mapper.RecruitMapper;
import com.dingli.framework.util.Response;
import com.dingli.service.IRecruitService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RecruitService implements IRecruitService {

    @Autowired
    private RecruitMapper recruitMapper;

    @Override
    public Response<PageInfo<Recruit>> Rtlist(String search, Integer pageNum, Integer pageSize) {
        if (pageNum == null) {
            pageNum = 1;
        }
        if (pageSize == null) {
            pageSize = 5;
        }
        PageHelper.startPage(pageNum, pageSize);
        PageInfo<Recruit> info = new PageInfo<>(recruitMapper.Rtlist(search));
        return new Response<>(200, "success", info);
    }

    @Override
    public Response<List<Recruit>> RtselectArea(String rtPoaition) {
        return new Response<>(200,"success", recruitMapper.RtselectArea(rtPoaition));
    }

    @Override
    public Response<Long> Rtinsert(Recruit recruit) {
        int count = recruitMapper.Rtinsert(recruit);
        if (count > 0) {
            return new Response(200, "success", recruit.getEseId());
        } else {
            return new Response<>(500, "failed");
        }
    }

    @Override
    public Response<Recruit> RtselectById(Long rtID) {
        return new Response(200, "success", recruitMapper.RtselectById(rtID));
    }

    @Override
    public Response<Object> RtupdateById(Recruit recruit) {
        int count = recruitMapper.RtupdateById(recruit);
        if (count > 0) {
            return new Response<>(200, "success");
        } else {
            return new Response<>(500, "failed");
        }
    }

    @Override
    public Response<Object> RtdeleteById(Long rtID) {
        int count = recruitMapper.RtdeleteById(rtID);
        if (count > 0) {
            return new Response<>(200, "success");
        } else {
            return new Response<>(500, "failed");
        }
    }

    @Override
    public Response<Object> RtupdateState(String rtID) {
        int count = recruitMapper.RtupdateState(rtID);
        if (count > 0) {
            return new Response<>(200, "success");
        } else {
            return new Response<>(500, "failed");
        }
    }

    @Override
    public Response<Object> Rtupdate(String rtID) {
        int count = recruitMapper.Rtupdate(rtID);
        if (count > 0) {
            return new Response<>(200, "success");
        } else {
            return new Response<>(500, "failed");
        }
    }

    @Override
    public Response<List<Recruit>> RtselectState(String reState) {
        List<Recruit> recruits = recruitMapper.RtselectState(reState);
        return new Response<>(200,"success", recruitMapper.RtselectState(reState));
    }

    @Override
    public Response<List<Recruit>> RtselectState1(String reState) {
        List<Recruit> recruits = recruitMapper.RtselectState1(reState);
        return new Response<>(200,"success", recruitMapper.RtselectState1(reState));
    }

    @Override
    public Response<List<Recruit>> RtAll(String rtID) {
        return new Response<>(200,"success", recruitMapper.RtAll(rtID));
    }

}
